package com.sun.dailyprj.designpatterns.chain;


public abstract class InterceptChain<T>{
    public String TAG;
    private InterceptChain next;

    public InterceptChain(String tag) {
        TAG = tag;
    }

    public void setNextInterceptChain(InterceptChain next){
        this.next = next;
    }

    abstract void next(String tag);

    abstract void cancel(String tag);

    abstract void other(String tag);

    public void handlerNext(String tag) {
        if(tag == null)
            return;
       if(tag.equals(TAG))
           this.next(tag);
       else
           if(next != null)
               next.handlerNext(tag);
           else
               System.out.print("handler next end");
    }

    public void handlerCancel(String tag) {
        if(tag == null)
            return;
        if(tag.equals(TAG))
            this.cancel(tag);
        else
            if(next != null)
                next.handlerNext(tag);
            else
                System.out.print("handler cancel end");
    }

    public void handlerOther(String tag) {
        if(tag == null)
            return;
        if(tag.equals(TAG))
            this.other(tag);
        else
            if(next!=null)
                next.handlerOther(tag);
            else
                System.out.print("handler other end");
    }


}
